package com.hyperboost.result;

import com.hyperboost.constant.HttpStatusConstant;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    /**
     * 业务状态码
     */
    private Integer code;
    /**
     * 业务提示信息
     */
    private String message;
    /**
     * 业务响应数据
     */
    private T data;

     /**
     * 成功响应
     *
     * @param message
     * @return 成功响应消息
     */
    public static <T> Result<T> success(String message) {
        Result<T> result = new Result<>();
        result.setCode(HttpStatusConstant.SUCCESS);
        result.setMessage(message);
        return result;
    }

    /**
     * 成功响应
     *
     * @param data
     * @return 成功响应数据
     */
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(HttpStatusConstant.SUCCESS);
        result.setData(data);
        return result;
    }

    /**
     * 成功响应
     *
     * @param message
     * @param data
     * @return 成功响应消息和数据
     */
    public static <T> Result<T> success(String message, T data) {
        Result<T> result = new Result<>();
        result.setCode(HttpStatusConstant.SUCCESS);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    /**
     * 失败响应
     *
     * @param message
     * @return 失败响应消息
     */
    public static <T> Result<T> error(String message) {
        Result<T> result = new Result<>();
        result.setCode(HttpStatusConstant.ERROR);
        result.setMessage(message);
        return result;
    }

    /**
     * 失败响应
     *
     * @param data
     * @return 失败响应数据
     */
    public static <T> Result<T> error(T data) {
        Result<T> result = new Result<>();
        result.setCode(HttpStatusConstant.ERROR);
        result.setData(data);
        return result;
    }

    /**
     * 失败响应
     *
     * @param message
     * @param data
     * @return 失败响应消息和数据
     */
    public static <T> Result<T> error(String message, T data) {
        Result<T> result = new Result<>();
        result.setCode(HttpStatusConstant.ERROR);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
}
